<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = ['哈士奇', '柯基', '秋田']
      // find 回调函数返回的 true 找到了 false 没找到
      // 找到一个元素就停止检索
      const res1 = arr.find(v => {
        console.log('find1-执行啦')
        if (v === '哈士奇') {
          return true
        } else {
          return false
        }
      })
      console.log('res1:', res1)
      // 找不到为空
      const res2 = arr.find(v => {
        console.log('find2-执行啦')
        if (v === '阿拉斯加') {
          return true
        } else {
          return false
        }
      })
      console.log('res2:', res2)

      // 对象数组
      const objArr = [
        { name: 'jack', age: 18 },
        { name: 'rose', age: 20 },
        { name: 'ice', age: 30 },
        { name: 'robot', age: 50 }
      ]
      const res3 = objArr.find(v => {
        // 比较年龄
        if (v.age >= 20) {
          return true
        }
      })
      console.log('res3:', res3)
    </script>
  </body>
</html>
